﻿using System;
using AgentListener.Controllers;
using AgentListener.DataProcessing;
using AgentListener.Mongo;
using Common.Configuration;
using Common.Configuration.Listener;
using Common.Configuration.Mongo;
using Microsoft.Practices.Unity;

namespace AgentListener
{
    public static class ContainerManager
    {
        private static readonly Lazy<UnityContainer> _container = new Lazy<UnityContainer>(() => new UnityContainer());
        private static UnityContainer Container {get { return _container.Value; }}

        private static void FillContainer()
        {
            Container.RegisterInstance<IListenerConfig>(ListenerConfig.Load())
                     .RegisterInstance<IMongoConfig>(MongoConfig.Load())
                     .RegisterType<IMongoProvider, MongoProvider>()
                     .RegisterType<IControllerFactory, ControllerFactory>()
                     .RegisterType<IContextProcessor, ContextProcessor>();
        }

        public static IListener GetListener()
        {
            FillContainer();
            return Container.Resolve<Listener>();
        }
    }
}